unit uManageCategories;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxContainer, cxEdit, cxCustomData, cxStyles, cxTL, cxLabel, cxMaskEdit,
  cxTLdxBarBuiltInMenu, DB, nxdb, cxInplaceContainer, cxDBTL, cxTLData,
  StdCtrls, cxTextEdit, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox, Grids, DBGrids;

type
  TfmCategories = class(TForm)
    lbl24: TLabel;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn1: TcxDBTreeListColumn;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    qryCategories: TnxQuery;
    qryCategoriesChildrens: TIntegerField;
    qryCategoriesCategoryName: TStringField;
    qryCategoriesLeafCategory: TBooleanField;
    qryCategoriesCategoryID: TIntegerField;
    qryCategoriesCategoryParentID: TIntegerField;
    qryCategoriesCategoryLevel: TIntegerField;
    qryCategoriesileaf: TSmallintField;
    qryCategoriesGlobalSiteID: TStringField;
    dsCategories: TDataSource;
    cxComboBox1: TcxComboBox;
    DBGrid1: TDBGrid;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure cxComboBox1PropertiesChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmCategories: TfmCategories;

implementation

uses uMain;

{$R *.dfm}

procedure TfmCategories.FormShow(Sender: TObject);
begin
  cxComboBox1.Properties.Items.Clear;
  fmMain.qryActiveSites.Open;
  fmMain.qryActiveSites.First;
  while not fmMain.qryActiveSites.Eof do begin
    cxComboBox1.Properties.Items.Add(fmMain.qryActiveSites.FieldValues['GlobalSiteID']);
    fmMain.qryActiveSites.Next;
  end;
  qryCategories.ParamByName('GlobalSiteID').AsString := cxComboBox1.EditValue;
  qryCategories.Open;
end;

procedure TfmCategories.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  qryCategories.Close;
  fmMain.qryActiveSites.Close;
end;

procedure TfmCategories.cxComboBox1PropertiesChange(Sender: TObject);
begin
  if qryCategories.ParamByName('GlobalSiteID').AsString <> cxComboBox1.EditValue then begin
    qryCategories.ParamByName('GlobalSiteID').AsString := cxComboBox1.EditValue;
    qryCategories.Close;
    qryCategories.Open;
  end;
end;

end.
